//
//  SinaWelcomeViewController.swift
//  MySinaWeiBoSwiftProject
//
//  Created by apple on 2016/11/15.
//  Copyright © 2016年 WangChen. All rights reserved.
//

import UIKit
import SnapKit
import SDWebImage

class SinaWelcomeViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = UIColor.white
        setupUI()
    }
    
    
    
    private lazy var iv_icon: UIImageView = UIImageView(image: #imageLiteral(resourceName: "avatar_default_big"))
    private lazy var lb_title: UILabel = UILabel(title: "欢迎回来", font: 18, color: UIColor.darkGray)
    
    //布局界面
    func setupUI() {
        
        view.addSubview(iv_icon)
        view.addSubview(lb_title)
        
        iv_icon.layer.cornerRadius = 42.5
        iv_icon.layer.masksToBounds = true
        iv_icon.sd_setImage(with: SinaUserAccountViewModel.shared.avatarLargeURL)
        lb_title.alpha = 0
        
        let width: CGFloat = 85
        
        iv_icon.snp.makeConstraints { (make) in
            make.centerX.equalTo(view)
            make.bottom.equalTo(view).offset(-180)
            make.size.equalTo(CGSize(width: width, height: width))
        }
        
        lb_title.snp.makeConstraints { (make) in
            make.centerX.equalTo(iv_icon)
            make.top.equalTo(iv_icon.snp.bottom).offset(20)
        }
        
    }
    
    //动画在这个里面做
    override func viewDidAppear(_ animated: Bool) {
        startAnim()
    }
    
    
    //开始动画
    func startAnim() {
        
        iv_icon.snp.updateConstraints { (make) in
            make.bottom.equalTo(view).offset(-(UIScreen.main.bounds.height - 180 - 85))
        }
        
        UIView.animate(withDuration: 1.5, delay: 0, usingSpringWithDamping: 0.3, initialSpringVelocity: 7, options: [], animations: {
            
            self.view.layoutIfNeeded()
            
        }, completion: {
            (res)->() in
            UIView.animate(withDuration: 0.5, animations: {
                self.lb_title.alpha = 1
            }, completion: { (Bool) in
//                UIApplication.shared.keyWindow?.rootViewController = SinaTabBarController()
                NotificationCenter.default.post(name: NSNotification.Name(changeRootVCNotification), object: nil)
            })
        })
    }
    
    
    
    

}




